package com.innovation.chengzhangriji.ui.widget;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.innovation.chengzhangriji.Config;
import com.innovation.chengzhangriji.R;
import com.nostra13.universalimageloader.core.ImageLoader;

public class DiscoverVideoViewHolder extends DiscoverViewHolder {

    public interface OnClickVideoListener {

        void onClickVideo(DiscoverVideoViewHolder holder);

    }

    private OnClickVideoListener onClickVideoListener;

    private ImageView imageThumbnail;

    public DiscoverVideoViewHolder(View itemView) {
        super(itemView);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.BELOW, R.id.image_user_head);
        getContent().setLayoutParams(params);
        View view = LayoutInflater.from(itemView.getContext()).inflate(R.layout.item_discover_video, getContent());
        imageThumbnail = (ImageView) view.findViewById(R.id.image_thumbnail);
        imageThumbnail.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (onClickVideoListener == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.image_thumbnail:
                onClickVideoListener.onClickVideo(this);
                break;
        }
    }

    public void setOnClickVideoListener(OnClickVideoListener onClickVideoListener) {
        this.onClickVideoListener = onClickVideoListener;
    }

    public void setVideoThumbnailUrl(String url) {
        ImageLoader.getInstance().displayImage(url, imageThumbnail, Config.getOptionsPhoto());
    }

}
